<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css" integrity="sha256-mUZM63G8m73Mcidfrv5E+Y61y7a12O5mW4ezU3bxqW4=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"zhengmingpei.gitee.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.8.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="前言hexo是一个使用了nodejs的静态博客生成器。可以使用markdown书写文档，然后使用hexo生成可读性更强的网页文件。 为什么使用hexo书写文档存在的问题写用于share的文档，太多时间用于使用office处理文档(一般是doc)中的代码，插图和正文的格式，效率过低，而且无法进行版本管理。 鉴于doc这类格式的缺点，推荐使用markdown。">
<meta property="og:type" content="article">
<meta property="og:title" content="设置hexo">
<meta property="og:url" content="https://zhengmingpei.gitee.io/2016/09/09/%E8%AE%BE%E7%BD%AEhexo/index.html">
<meta property="og:site_name" content="郑明培的个人博客">
<meta property="og:description" content="前言hexo是一个使用了nodejs的静态博客生成器。可以使用markdown书写文档，然后使用hexo生成可读性更强的网页文件。 为什么使用hexo书写文档存在的问题写用于share的文档，太多时间用于使用office处理文档(一般是doc)中的代码，插图和正文的格式，效率过低，而且无法进行版本管理。 鉴于doc这类格式的缺点，推荐使用markdown。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2016-09-09T07:00:00.000Z">
<meta property="article:modified_time" content="2021-11-28T04:35:16.239Z">
<meta property="article:author" content="zhengmingpei">
<meta property="article:tag" content="折腾">
<meta property="article:tag" content="hexo">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://zhengmingpei.gitee.io/2016/09/09/%E8%AE%BE%E7%BD%AEhexo/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://zhengmingpei.gitee.io/2016/09/09/%E8%AE%BE%E7%BD%AEhexo/","path":"2016/09/09/设置hexo/","title":"设置hexo"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>设置hexo | 郑明培的个人博客</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">郑明培的个人博客</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives" rel="section"><i class="archive fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-about"><a href="/about" rel="section"><i class="user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories" rel="section"><i class="th fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags" rel="section"><i class="tags fa-fw"></i>标签</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%89%8D%E8%A8%80"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A8hexo"><span class="nav-number">2.</span> <span class="nav-text">为什么使用hexo</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B9%A6%E5%86%99%E6%96%87%E6%A1%A3%E5%AD%98%E5%9C%A8%E7%9A%84%E9%97%AE%E9%A2%98"><span class="nav-number">2.1.</span> <span class="nav-text">书写文档存在的问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFmarkdown"><span class="nav-number">2.2.</span> <span class="nav-text">什么是markdown</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#markdown%E6%A0%BC%E5%BC%8F%E4%B8%8E%E5%85%B6%E4%BB%96%E6%A0%BC%E5%BC%8F%E6%96%87%E6%9C%AC%E7%9A%84%E8%BD%AC%E6%8D%A2%E9%97%AE%E9%A2%98"><span class="nav-number">2.3.</span> <span class="nav-text">markdown格式与其他格式文本的转换问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#hexo"><span class="nav-number">2.4.</span> <span class="nav-text">hexo</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AE%E5%92%8C%E4%BD%BF%E7%94%A8hexo"><span class="nav-number">3.</span> <span class="nav-text">如何配置和使用hexo</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85nodejs"><span class="nav-number">3.1.</span> <span class="nav-text">安装nodejs</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85hexo"><span class="nav-number">3.2.</span> <span class="nav-text">安装hexo</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%8D%9A%E5%AE%A2"><span class="nav-number">3.3.</span> <span class="nav-text">创建博客</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%A2%84%E8%A7%88%E5%8D%9A%E5%AE%A2"><span class="nav-number">3.4.</span> <span class="nav-text">预览博客</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E5%8D%9A%E5%AE%A2"><span class="nav-number">3.5.</span> <span class="nav-text">配置博客</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0%E6%96%87%E7%AB%A0"><span class="nav-number">3.6.</span> <span class="nav-text">添加文章</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">zhengmingpei</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives">
          <span class="site-state-item-count">36</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags">
        <span class="site-state-item-count">41</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/zhengmingpei" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengmingpei" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/zhengmingpei" title="gitee → https:&#x2F;&#x2F;gitee.com&#x2F;zhengmingpei" rel="noopener" target="_blank">gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://space.bilibili.com/32918983" title="bilibili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;32918983" rel="noopener" target="_blank">bilibili</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://zhengmingpei.gitee.io/2016/09/09/%E8%AE%BE%E7%BD%AEhexo/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="zhengmingpei">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="郑明培的个人博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          设置hexo
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2016-09-09 15:00:00" itemprop="dateCreated datePublished" datetime="2016-09-09T15:00:00+08:00">2016-09-09</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-11-28 12:35:16" itemprop="dateModified" datetime="2021-11-28T12:35:16+08:00">2021-11-28</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%9C%A8%E5%8C%97%E4%BA%AC/" itemprop="url" rel="index"><span itemprop="name">在北京</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>hexo是一个使用了nodejs的静态博客生成器。可以使用markdown书写文档，然后使用hexo生成可读性更强的网页文件。</p>
<h2 id="为什么使用hexo"><a href="#为什么使用hexo" class="headerlink" title="为什么使用hexo"></a>为什么使用hexo</h2><h3 id="书写文档存在的问题"><a href="#书写文档存在的问题" class="headerlink" title="书写文档存在的问题"></a>书写文档存在的问题</h3><p>写用于share的文档，太多时间用于使用office处理文档(一般是doc)中的代码，插图和正文的格式，效率过低，而且无法进行版本管理。</p>
<p>鉴于doc这类格式的缺点，推荐使用markdown。</p>
<span id="more"></span>

<h3 id="什么是markdown"><a href="#什么是markdown" class="headerlink" title="什么是markdown"></a>什么是markdown</h3><p>Markdown实质上是一种标记语言，其出现的目的就是为了把文档编写者从复杂的格式整理中解放出来，将更多的精力放在内容上；而因其语法简单清晰，所以迅速风靡，现在github的项目文档多数都是markdown格式，例如readme.md。</p>
<h3 id="markdown格式与其他格式文本的转换问题"><a href="#markdown格式与其他格式文本的转换问题" class="headerlink" title="markdown格式与其他格式文本的转换问题"></a>markdown格式与其他格式文本的转换问题</h3><p>虽然markdown拥有上述优点，并因之风靡于网络，但传统的PDF格式仍旧被大量使用。鉴于此，有多种方案用来实现markdown与PDF格式的转换。</p>
<p>但是多数方案都或受限于网络，或受限于tex套件和pandoc等。因此推荐将markdown转换为html，然后使用浏览器预览的方式，加强阅读体验，还可以使用浏览器的打印功能输出最后的PDF。</p>
<h3 id="hexo"><a href="#hexo" class="headerlink" title="hexo"></a>hexo</h3><p>hexo可以根据你的markdown文件构建一个本地web站点，并实现站点的预览，其核心就是将markdown文件转换成html的一种转换器。</p>
<h2 id="如何配置和使用hexo"><a href="#如何配置和使用hexo" class="headerlink" title="如何配置和使用hexo"></a>如何配置和使用hexo</h2><h3 id="安装nodejs"><a href="#安装nodejs" class="headerlink" title="安装nodejs"></a>安装nodejs</h3><p>从nodejs的官网下载稳定版的nodejs的压缩包，解压后，将其bin目录放在PATH下。</p>
<p>运行：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">node -v</span><br></pre></td></tr></table></figure>

<p>可以查看到node的版本号，即表示系统可以找到nodejs并成功运行。</p>
<p>运行：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm -v</span><br></pre></td></tr></table></figure>

<p>可以查看到npm的版本号，即表示系统可以找到nodejs的包管理器npm并成功运行。</p>
<h3 id="安装hexo"><a href="#安装hexo" class="headerlink" title="安装hexo"></a>安装hexo</h3><p>在成功安装好上面的npm后，运行：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm install hexo-cli</span><br></pre></td></tr></table></figure>

<p>即可为当前用户安装hexo，具体的安装目录大致在~/node_modules, 然后添加<code> ~/node_modules/hexo-cli/bin/</code>到PATH下。</p>
<p>运行：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">hexo -v</span><br></pre></td></tr></table></figure>

<p>可以查看hexo-cli的版本即表示hexo安装成功。</p>
<h3 id="创建博客"><a href="#创建博客" class="headerlink" title="创建博客"></a>创建博客</h3><p>hexo安装成功后，可以创建博客了。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">hexo init blog</span><br></pre></td></tr></table></figure>

<p>上面的命令可以初始化一个blog目录，也就是静态博客网站的根目录。</p>
<h3 id="预览博客"><a href="#预览博客" class="headerlink" title="预览博客"></a>预览博客</h3><p>启动博客的本地预览，只需cd到上面的根目录，然后<code>hexo serve</code>即可，默认的访问地址是<code>http://localhost:4000/</code></p>
<p>即：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cd</span> blog</span><br><span class="line">hexo s</span><br></pre></td></tr></table></figure>

<p>通过浏览器打开上面的网址，即可预览博客。</p>
<h3 id="配置博客"><a href="#配置博客" class="headerlink" title="配置博客"></a>配置博客</h3><p>配置文件是_config.yml，在blog目录下，里面可以设置文章标题格式，作者名称等。</p>
<h3 id="添加文章"><a href="#添加文章" class="headerlink" title="添加文章"></a>添加文章</h3><p>创建文章，标题即引号中的内容。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">hexo new post <span class="string">&quot;HelloWorld&quot;</span></span><br></pre></td></tr></table></figure>

<p>创建页面，可以理解为创建一个目录，目录下创建一个<code>index.md</code>。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">hexo new page about</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%8A%98%E8%85%BE/" rel="tag"># 折腾</a>
              <a href="/tags/hexo/" rel="tag"># hexo</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2016/09/05/%E4%BD%BF%E7%94%A8%E8%84%9A%E6%9C%AC%E4%BB%8E%E7%BD%91%E9%A1%B5%E6%89%B9%E9%87%8F%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6/" rel="prev" title="使用脚本从网页批量下载文件">
                  <i class="fa fa-chevron-left"></i> 使用脚本从网页批量下载文件
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2016/09/12/LinuxShellScriptingCookbook1/" rel="next" title="LinuxShellScriptingCookbook1">
                  LinuxShellScriptingCookbook1 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">zhengmingpei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
